const mongoose = require("mongoose");

//管理员登录
const login = async ({ username, password }) => {
    const adModel = mongoose.model("adminsModel");
    const data = await adModel.findOne({ adminName: username, adminPassword: password });
    console.log(data);
    let status = true;
    if (data) {
        console.log(status);
        return {status,data};
    } else {
        status = false;
        return status;
    }
};


//管理员注册

const reg = async ({ username, password }) => {
    const adminsModel = mongoose.model("adminsModel");
    

    const data = await adminsModel.create({ adminName: username, adminPassword: password })
    const admin = await adminsModel.findOne({ _id: data._id });
    let status = true;
    if (admin) {
        return status;
    } else {
        status = false;
        return status;
    }

};

module.exports = { login, reg }